<template>
  <div class="app-container">
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true"> 
        <el-form-item label="关键词：" prop="">
          <el-input v-model="queryParams.keyWord" placeholder="请输入卡名称\卡号\退款单号\店铺名称" clearable style="width: 300px" />
        </el-form-item>
        <el-form-item label="查询用户：" prop="">
          <el-input v-model="queryParams.user" placeholder="请输入手机号" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="申请时间：" prop="">
          <el-date-picker v-model="date" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="卡类型：" prop="">
          <el-select v-model="queryParams.cardType" placeholder="请选择" filterable clearable :style="{width: inputWidth}">
            <el-option v-for="dict in cardTypeLs" :key="dict.id" :label="dict.value" :value="dict.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="店铺：" prop="">
          <el-select v-model="queryParams.shopId" placeholder="请选择" filterable clearable :style="{width: inputWidth}">
            <el-option v-for="(item,index) in shopList" :key="index" :label="item.value" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="退款状态：" prop="">
          <el-select v-model="queryParams.status" placeholder="请选择" filterable clearable :style="{width: inputWidth}">
            <el-option v-for="(item,index) in returnStatusLs" :key="index" :label="item.value" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>

        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <el-table v-loading="loading" :data="tabList" stripe border>
        <el-table-column label="序号" align="center" type="index" width="64px" />
        <el-table-column label="店铺名称" align="center" prop="shopName" />
        <el-table-column label="退卡单号" align="center" prop="returnOrderNo" />
        <el-table-column label="申请时间" align="center" prop="refundTime" width="100" />
        <el-table-column label="退卡人手机号" align="center" prop="phone" />
        <el-table-column label="卡类型" align="center" prop="cardTypeDict" />
        <el-table-column label="卡名称" align="center" prop="cardName" />
        <el-table-column label="卡号" align="center" prop="cardNo" />
        <el-table-column label="购卡金额" align="center" prop="payMoney" />
        <el-table-column label="现金余额" align="center" prop="cashBalance" />
        <el-table-column label="卡余额" align="center" prop="usable" />
        <el-table-column label="管存余额" align="center" prop="depositMoney" />
        <el-table-column label="退款金额" align="center" prop="money" />
        <el-table-column label="退款状态" align="center" prop="statusDict" />
        <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="examineDialogClick(scope.row)">审核记录</el-button>
            <el-button size="mini" type="text" @click="useClick(scope.row)">卡使用记录</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
      <!-- 审核记录弹窗 -->
      <ExamineDialog :id="dialogId" v-bind="$attrs" v-if="dialogVisible" :visible.sync="dialogVisible"
        @success="_handleSuccess">
      </ExamineDialog>
      <!-- 使用记录弹窗 -->
      <UseRecordDialog :customerCardId="customerCardId" :customerId="customerId" v-bind="$attrs" v-if="useDialogVisible" :visible.sync="useDialogVisible"
        @success="_handleSuccess">
      </UseRecordDialog>
    </div>
  </div>
</template>

<script>
  import {
    adminCustomerCardReturnList,
    shopSelect,
  } from "@/api/moneyManagement";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  import ExamineDialog from "@/views/moneyManagement/cardRefundQuery/components/examineDialog";
  import UseRecordDialog from "@/views/moneyManagement/cardRefundQuery/components/useRecordDialog";
  export default {
    // dicts: ['equity_card_issue_type', 'equity_card_sell_status'],
    name: "",
    components: {
      ExportExcelButton,
      ExamineDialog,
      UseRecordDialog
    },
    data() {
      return {
        labelWidth: '100px',
        inputWidth: '200px',
        //日期
        date: [],
        // 遮罩层
        loading: false,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 表格数据
        tabList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          cardType: '', //卡类型 asset_card_type 2计次卡 3计费卡 4课时卡
          endDate: '', //申请时间结束
          startDate: '', //申请时间开始
          keyWord: '', //关键字
          shopId: '', //店铺id
          status: '', //退卡状态 asset_experience_return_status 1待退款 3同意退款 5拒绝退款
          user: '', //查询用户
        },
        cardTypeLs: [], //卡类型下拉
        returnStatusLs: [{
          id: "",
          value: "全部",
        }, {
          id: "1",
          value: "待审核",
        }, {
          id: "3",
          value: "同意退款",
        }, {
          id: "5",
          value: "拒绝退款",
        }], //退卡状态下拉
        shopList: [], //店铺下拉
        info: {},
        dialogVisible: false, //审核弹窗状态
        useDialogVisible: false, //使用记录弹窗状态
        orderType: '', //券类型
        dialogId: '', //弹窗id
        customerCardId:'',//卡id
        customerId:'',//用户id
      };
    },
    computed: {
      ExportParams() {
        const params = {
          ...this.queryParams,
        };
        return params;
      },
    },
    created() {
      this.getCardType();
      // this.getReturnStatus();
      this.getShopSelect();
      this.getList();
    },
    methods: {
      //获取卡类型字典
      getCardType() {
        var dictType = "asset_card_type";
        this.$getSelectList(dictType)
          .then((res) => {
            var arr = [{
              id: "",
              value: "全部",
            }, ];
            this.cardTypeLs = arr.concat(res.result[0].dictList);
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取退卡状态字典
      getReturnStatus() {
        var dictType = "asset_experience_return_status";
        this.$getSelectList(dictType)
          .then((res) => {
            var arr = [{
              id: "",
              value: "全部",
            }, ];
            this.returnStatusLs = arr.concat(res.result[0].dictList);
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //店铺查询
      getShopSelect() {
        var data = {}
        shopSelect(data).then(res => {
          var arr = [{
            id: "",
            value: "全部",
          }, ];
          this.shopList = arr.concat(res.result);
        });
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        adminCustomerCardReturnList(this.queryParams).then(response => {
          this.tabList = response.result.records;
          this.total = response.result.total;
          this.loading = false;
        });
      },
      // 表单重置
      resetQuery() {
        this.date = []
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          cardType: '', //卡类型 asset_card_type 2计次卡 3计费卡 4课时卡
          endDate: '', //申请时间结束
          startDate: '', //申请时间开始
          keyWord: '', //关键字
          shopId: '', //店铺id
          status: '', //退卡状态 asset_experience_return_status 1待退款 3同意退款 5拒绝退款
          user: '', //查询用户
        }
        // this.resetForm("form");
        this.getList();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.startDate = this.date[0];
        this.queryParams.endDate = this.date[1];
        this.queryParams.pageNum = 1;
        this.getList();
      },
      useClick(item) { //使用记录
        this.customerId = item.customerId
        this.customerCardId = item.cardId
        this.useDialogVisible = true
      },
      examineDialogClick(item) { //审核记录弹窗
        this.dialogId = item.id
        this.dialogVisible = true
      },
      _handleSuccess(e) {
        //成功回调
        // this.resetQuery()
        this.getList()
      },
    }
  };

</script>
<style scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .listBox_head {
    width: 100%;
    padding-bottom: 20px;
  }

  .num_detail {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    border: 1px solid #dfe6ec;
    border-radius: 10px;
    padding: 20px 10px 0;
    margin-bottom: 20px;
  }

  .num_detail_box {
    color: #333;
    font-size: 15px;
    margin-right: 30px;
    margin-bottom: 20px;
  }

</style>
